package com.example.demospringboot.controller.depcontroller;

import com.example.demospringboot.domains.Department;
import com.example.demospringboot.domains.Employee;
import com.example.demospringboot.mapper.DepartmentMapper;
import com.example.demospringboot.mapper.EmployeeMapper;
import com.google.gson.JsonObject;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    private static Logger logger = LoggerFactory.getLogger(DepartmentController.class);

    @Autowired
    DepartmentMapper deptMapper;

	@Autowired
    EmployeeMapper empMapper;

    @GetMapping("/dept/{deptCode}")
    public Department getDepartmentByCode(@PathVariable String deptCode){
        Department dept = deptMapper.getDepartmentByDeptCode(deptCode);
        return dept;
    }


    @GetMapping("/{deptCode}")
    public List<Employee> getEmployeeByDeptCode(@PathVariable String deptCode){
        return empMapper.getEmployeeByDeptCode(deptCode);
    }


    @ApiOperationSupport(params = @DynamicParameters(name = "ClassNameUUID81aecb92a276",properties = {
            @DynamicParameter(name = "deps",value = "在哪些部门",example = "第一部门",required = true),
            @DynamicParameter(name = "type",value = "哪种类型",example = "3",required = true,dataTypeClass = Integer.class)
    })
            ,responses = @DynamicResponseParameters(properties = {
            @DynamicParameter(value = "返回状态",name = "result", example = "0", required = true, dataTypeClass = Integer.class),
            @DynamicParameter(value = "描述",name = "desc"),
            @DynamicParameter(value = "结果形式",name = "para",dataTypeClass = Employee.class )
    })
    )
    @ApiOperation(value = "自定义参数查询部门相关信息1")
    @RequestMapping(value="/cusSearchDep",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public JsonObject cutSearchDep(
            @RequestBody JsonObject jsonObject){
        //logger.info("begin custom search " + jsonObject.toString());
        JsonObject jsonObject2 = new JsonObject();
        jsonObject2.addProperty("result",0);
        jsonObject2.addProperty("desc","成功");
        jsonObject2.addProperty("para","暂时为空");
        String strTmp = jsonObject2.toString();
        logger.info("stTmp is "  + strTmp);
        return jsonObject2;
    }

    @ApiOperationSupport(params = @DynamicParameters(name = "ClassNameUUID1191aecb92a276",properties = {
            @DynamicParameter(name = "deps",value = "在哪些部门",example = "第二部门",required = true),
            @DynamicParameter(name = "type",value = "哪种类型",example = "2",required = true,dataTypeClass = Integer.class)
    })
    )
    @ApiOperation(value = "自定义参数查询部门相关信息2")
    @RequestMapping(value="/cusSearchDep2",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String cutSearchDep2(
            @RequestBody String strTmp2){
        logger.info("begin custom search 2 " + strTmp2);
        JsonObject jsonObject3 = new JsonObject();
        String strTmp = "aaaa";
        logger.info("stTmp is "  + strTmp);
        return strTmp;
    }

    @ApiOperationSupport(params = @DynamicParameters(name = "ClassNameUUID2293aecb92a276",properties = {
            @DynamicParameter(name = "deps",value = "在哪些部门",example = "第三部门",required = true),
            @DynamicParameter(name = "type",value = "哪种类型",example = "3",required = true,dataTypeClass = Integer.class)
    })
    )
    @ApiOperation(value = "自定义参数查询部门相关信息3")
    @RequestMapping(value="/cusSearchDep3",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String cutSearchDep3(
            @RequestBody JsonObject jsonObject){
        logger.info("begin custom search 3 " + jsonObject.toString());

        String strTmp = "aaaa";
        logger.info("stTmp is "  + strTmp);
        return strTmp;
    }
}
